Technote 1148Dialog Manager Helper FunctionsBy C.K. HaunRevised by Mark Cookson Apple Worldwide Developer Technical Support |
CONTENTSIntroduction |
This Technote discusses Dialog Manager calls available since System 7.0 which can ease the work of managing dialogs. They allow you to call on the services of the System to track the mouse cursor (i.e., change to and from the I-beam cursor) and handle the standard keystrokes for accept and cancel in your dialog. |
IntroductionWith the introduction of System 7.0 some new Dialog Manager calls were added to make creating standard dialog functionality simpler for the developer. The functionality that has been simplified is:
|
System 7 Dialog Manager Call InterfacesThe new calls are:
The
|
Using the callsUsing these calls requires a little preparation on your part. After you create your dialog, you need to tell the Dialog Manager which items you want as the default and cancel items. The button selected as the cancel item will be toggled by the Escape key or by a Command-. keypress. The button specified as the default will be toggled by the Return or Enter key, and also will have the standard heavy black border drawn around it. The buttons will also be hilited when the correct key is hit. SetDialogTracksCursor tells the Dialog Manager
that it should set the cursor on behalf of your application
according to what part of the dialog the mouse is hovering
over. When you pass a ' Here is a snippet of code showing how to call the functions described in this Technote: |
/* Before we go into a ModalDialog loop, do a little preparation */ ModalFilterUPP filterProcUPP; myDialogPtr = GetNewDialog (kMyDialogID, nil, (WindowPtr)-1); /* Tell the Dialog Manager that the OK button is the default */ myErr = SetDialogDefaultItem (myDialogPtr, ok); /* Tell the Dialog Manager the cancel button is the cancel item*/ myErr = SetDialogCancelItem (myDialogPtr, cancel); /* We have an edit item in our dialog, so tell the Dialog Manager to change the cursor to an I-Beam when it's over the edit line */ myErr = SetDialogTracksCursor (myDialogPtr, true); filterProcUPP = NewModalFilterProc (ModalDialogFilter); do { ModalDialog (filterProcUPP, &hitItem); switch (hitItem) { case ...: break; case ...: break; default: } } while (hitItem != ok && hitItem != cancel); DisposeRoutineDescriptor (filterProcUPP); |
Your modal dialog filter will look something like this:
Boolean ModalDialogFilter (DialogPtr theDialog, EventRecord *theEvent, short *itemHit) { Boolean result = false; OSErr err = noErr; ModalFilterUPP standardProc; if ((theEvent->what == updateEvt) && (WindowPtr)theEvent->message != theDialog) { err = DispatchWindowUpdate ((WindowPtr)theEvent->message); } else if ((theEvent->what == activateEvt) && (WindowPtr)theEvent->message != theDialog) { DoActivate (theEvent, true); } else { err = GetStdFilterProc (&standardProc); if (err == noErr) { result = CallModalFilterProc (standardProc, theDialog, theEvent, itemHit); } } return result; } |
ConclusionBy using these Dialog Manager calls (even when you're not using a filter) you give your dialog a more consistent user interface and can save yourself a fair amount of work over doing it all yourself. |
Thanks to Pete Gontier.